# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=function2
pkgver=4.2.4
pkgrel=1
pkgdesc="An improved drop-in replacement to std::function"
arch=(any)
url="https://naios.github.io/function2/"
license=(Boost)
makedepends=(
  cmake
  gtest
)
source=(
  $pkgname-$pkgver.tar.gz::https://github.com/Naios/$pkgname/archive/refs/tags/$pkgver.tar.gz
  $pkgname-4.2.0-system_gtest.patch
  $pkgname-4.2.0-skip_docs.patch
)
sha512sums=('a70cc4d5cdcd9a108c930ef6f18662f649405b2c6d0c0e25526af555392503f467bfa7755d0f00651ad61c339102315cc2a1c9354326433bfaa3f8110517a79c'
            'fe7e5802dc150d415b43fecaf88d1fae3c38389844135bb20d66a577aa24d811ab9be9d662dcc03504eff77a54f2a42ba3516ae0f7d4ec552db39de78b7b1df1'
            'fec342025298f2a74e1b1daf381ff80b13cdc6238577379a1d805f3e38e26c8d40a24e7894d943fcb1a1dd27dafb22b521c8e6847e0d155400871bcec0e15681')
b2sums=('1c149140351bf9551a3ab51ba4cdb6f79c213aea7ec4eedfe75f9b1846836af19e12c4448779fd200c4ac631613f67d526d96460de64fbf7dfbdef2b7a56c9ae'
        'ec067d26551b1139acd133b04bf89a67d314e21025e39b38d9bdc134ba50eb58f8903eb6668a487bf07f29e308bd9b55a7aed90befbed06f48eaf020245a4535'
        '83f7efdbaa4032716cc6a3718c8c6a1028961862c1305ebd39c2665da705fbe2ed66cd9d1806697436bdbedc2e60aa86403547e7f47fb1edfe01361253e36b20')

prepare() {
  # use the system installed gtest
  patch -Np1 -d $pkgname-$pkgver -i ../"$pkgname-4.2.0-system_gtest.patch"
  # skip installing docs (to a wrong location)
  patch -Np1 -d $pkgname-$pkgver -i ../"$pkgname-4.2.0-skip_docs.patch"
}

build() {
  local cmake_options=(
    -B build
    -D CMAKE_BUILD_TYPE=None
    -D CMAKE_INSTALL_PREFIX=/usr
    -S $pkgname-$pkgver
    -W no-dev
  )

  cmake "${cmake_options[@]}"
  cmake --build build --verbose
}

check() {
  ctest --test-dir build --output-on-failure
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  install -vDm 644 "$pkgname-$pkgver/Readme.md" -t "$pkgdir/usr/share/doc/$pkgname/"
}
